//
//  RZPluginBoardItem.m
//  RZIM
//
//  Created by reyzhang on 2021/8/18.
//

#import "RZPluginBoardItem.h"
#import "RZIMConfig.h"


@implementation RZPluginBoardItem

- (instancetype)initWithTitle:(NSString *)title normalImage:(UIImage *)normalImage highlightedImage:(UIImage *)highlightedImage tag:(NSInteger)tag{
    self = [super init];
    if (self) {
        self.title = title;
        self.normalImage = normalImage;
        self.highlightedImage = highlightedImage;
        super.tag = tag;
    }
    return self;
}

- (void)loadView {
    UIView *myView = [UIView new];
    UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [imageButton setImage:self.normalImage forState:UIControlStateNormal];
    if (self.highlightedImage) {
        [imageButton setImage:self.highlightedImage forState:UIControlStateHighlighted];
    }
    [myView addSubview:imageButton];
    [imageButton addTarget:self action:@selector(imageButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
    imageButton.frame = CGRectMake((CGRectGetWidth(self.frame)- self.normalImage.size.width)/2, 0, self.normalImage.size.width, self.normalImage.size.height);
    
    UILabel *label = [UILabel new];
    [label setText:_title];
    [label setTextColor:[UIColor colorWithRed:163/255.0 green:168/255.0 blue:175/255.0 alpha:1]];
    [label setFont:[RZIMConfigCenter.font fontOfAssistantLevel]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [myView addSubview:label];
    label.frame = CGRectMake(0, CGRectGetMaxY(imageButton.frame) + 5.5, CGRectGetWidth(self.frame), 14);
    [self.contentView addSubview:myView];

    // add contraints
//    [myView setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [imageButton setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [label setTranslatesAutoresizingMaskIntoConstraints:NO];
//
//    [self.contentView
//        addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[myView(75)]|"
//                                                               options:kNilOptions
//                                                               metrics:nil
//                                                                 views:NSDictionaryOfVariableBindings(myView)]];
//    [self.contentView
//        addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[myView]|"
//                                                               options:kNilOptions
//                                                               metrics:nil
//                                                                 views:NSDictionaryOfVariableBindings(myView)]];
//
//    [self.contentView
//        addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-7.5-[imageButton(60)]"
//                                                               options:kNilOptions
//                                                               metrics:nil
//                                                                 views:NSDictionaryOfVariableBindings(imageButton)]];
//
//    [self.contentView
//        addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label]|"
//                                                               options:kNilOptions
//                                                               metrics:nil
//                                                                 views:NSDictionaryOfVariableBindings(label, myView)]];
//    [self.contentView
//        addConstraints:[NSLayoutConstraint
//                           constraintsWithVisualFormat:@"V:|[imageButton(60)]-5.5-[label(14)]"
//                                               options:kNilOptions
//                                               metrics:nil
//                                                 views:NSDictionaryOfVariableBindings(label, imageButton)]];
}

- (void)imageButtonTouchUpInside {
    self.Itemclick();
}

@end
